// Disable debug console on Windows platform
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use tauri::generate_context;
use tracing_appender::{non_blocking, rolling};

use crate::config::db_conn::init_db;

mod config;
mod entity;
mod handler;
mod util;

#[tokio::main]
async fn main() {
    // init sqlite3 db
    let file_appender = rolling::daily("Logs", "runtime.log");

    let (non_blocking_appendr, _guard) = non_blocking(file_appender);

    // init tacing_subscriber
    use tracing_subscriber::{fmt::format::FmtSpan, EnvFilter};

    unsafe {}

    tracing::info!("init database ...");
    init_db().await;

    tracing::info!("init database works ...");

    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![
            crate::handler::task_cmd::add_task,
            // crate::handler::task_cmd::control_task,
            crate::handler::task_cmd::query_task,
            crate::handler::task_cmd::query_task_statics,
            // crate::handler::task_cmd::add_tomato_task,
            crate::handler::goals_cmd::add_goals,
            crate::handler::goals_cmd::query_goals,
            // crate::handler::goals_cmd::query_goals_detail,
            crate::handler::ring_cmd::stop_music,
            crate::handler::ring_cmd::start_music,
            crate::handler::todo_cmd::add_todo,
            crate::handler::todo_cmd::query_todo,
            crate::handler::todo_cmd::add_to_task,
        ])
        .run(generate_context!("tauri.conf.json"))
        .expect("error when running tauri app, maybe parse tauri.conf.json failed");
}
